mudbox::Error Class Reference

#include <error.h>

List of all members.


Detailed Description

Holds information about an error. Typically heap allocated.

Objects of this class are usually created on the heap and used in exception handling in the following way:

    try
    {
        MyFunction();
    }
    catch( Error *pError )
    {
       // report the error to the user, and delete the object.
       pError->Report();
       ... do something here to handle the problem
    }
In MyFunction somewhere you can write:
    ...
    if ( pPointer == 0 )
        throw new Error( "No object specified" );
    ...
You should use the MB_ERROR macro to throw Errors:
    MB_ERROR( "No pointer specified in step %d", iStep );
See the macro MB_ERROR for more details.

Public Types

enum   Code {
  codeOk, codeOutOfMemory, codeHardwareFailure, codeOutOfVideoMemory,
  codeUnspecified
}

Public Member Functions

  Error (const QString &sMessage, Code eCode=codeUnspecified, const char *pFunction=0, const char *pSourceFileName=0, unsigned int iLine=0)
  Constructor.
Error Format (const char *pMessage,...)
  Sets the message in the error using printf-like formatting. Returns a pointer to itself.
enum Code  Code (void) const
  Returns the error code associated with the error.
const QString &  Message (void) const
  Returns the error message associated with the error.
void  Report (const QString &sPre="") const
  Reports the error to the user in a message box and deletes the Error object.
void  Discard (void) const
  Discards the error message and deletes the object (except s_cBadAlloc errors, which should never be deleted.).

Static Public Member Functions

void  ThrowBadAlloc (void)
  Throws a static bad alloc exception. (No memory allocation is required to report allocation problems.).

Public Attributes

enum mudbox::Error::Code  m_eCode

Static Public Attributes

Error  s_cBadAlloc

Member Enumeration Documentation

enum mudbox::Error::Code
 
Enumeration values:
codeOk 
codeOutOfMemory 
codeHardwareFailure 
codeOutOfVideoMemory 
codeUnspecified 
00056     {
00057         codeOk,
00058         codeOutOfMemory,
00059         codeHardwareFailure,
00060         codeOutOfVideoMemory,
00061         codeUnspecified
00062     } m_eCode;

Constructor & Destructor Documentation

mudbox::Error::Error const QString &  sMessage,
Code  eCode = codeUnspecified,
const char *  pFunction = 0,
const char *  pSourceFileName = 0,
unsigned int  iLine = 0
 

Constructor.

How this is usually used:

        throw new Error( "Some message" );
Parameters:
sMessage  [in] Message that explains the error
eCode  [in] Error code (optional)
pFunction  [in] Name of the function where the error happens (optional)
pSourceFileName  [in] Name of the source files where the error happens (optional)
iLine  [in] Line number in the source file where the error happens (optional)

Member Function Documentation

Error* mudbox::Error::Format const char *  pMessage,
  ...
 

Sets the message in the error using printf-like formatting. Returns a pointer to itself.

Call this method with the same arugments you would use for printf.

enum Code mudbox::Error::Code void   )  const
 

Returns the error code associated with the error.

const QString& mudbox::Error::Message void   )  const
 

Returns the error message associated with the error.

void mudbox::Error::Report const QString &  sPre = ""  )  const
 

Reports the error to the user in a message box and deletes the Error object.

Errors are written into the log file, and also reported in a message box that the user must dismiss. If you specify a pretext string, it will be displayed first. After reporting is complete, the Error object will be deleted in this call (except s_cBadAlloc errors, which don't reside in deletable space.)

Parameters:
sPre  [in] Optional string describing the pretext of the error
void mudbox::Error::Discard void   )  const
 

Discards the error message and deletes the object (except s_cBadAlloc errors, which should never be deleted.).

void mudbox::Error::ThrowBadAlloc void   )  [inline, static]
 

Throws a static bad alloc exception. (No memory allocation is required to report allocation problems.).

00107 { throw &s_cBadAlloc; };

Member Data Documentation

enum mudbox::Error::Code mudbox::Error::m_eCode
 
Error mudbox::Error::s_cBadAlloc [static]
 

mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error
mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error mudbox::Error